
import java.io.*;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
//import goldengine.java.*;

/*
 * Licensed Material - Property of Matthew Hawkins (hawkini@4email.net) 
 */
 
public class Descafeinado implements GPMessageConstants
{
 
    private interface SymbolConstants 
    {
       final int SYMBOL_EOF               =  0;  // (EOF)
       final int SYMBOL_ERROR             =  1;  // (Error)
       final int SYMBOL_WHITESPACE        =  2;  // (Whitespace)
       final int SYMBOL_APOST             =  3;  // ''
       final int SYMBOL_MINUS             =  4;  // '-'
       final int SYMBOL_PIPEPIPE          =  5;  // ' ||'
       final int SYMBOL_CHAR              =  6;  // ' char '
       final int SYMBOL_EXCLAM            =  7;  // '!'
       final int SYMBOL_EXCLAMEQ          =  8;  // '!='
       final int SYMBOL_PERCENT           =  9;  // '%'
       final int SYMBOL_AMPAMP            = 10;  // '&&'
       final int SYMBOL_LPARAN            = 11;  // '('
       final int SYMBOL_RPARAN            = 12;  // ')'
       final int SYMBOL_TIMES             = 13;  // '*'
       final int SYMBOL_COMMA             = 14;  // ','
       final int SYMBOL_DOT               = 15;  // '.'
       final int SYMBOL_DIV               = 16;  // '/'
       final int SYMBOL_SEMI              = 17;  // ';'
       final int SYMBOL_LBRACKET          = 18;  // '['
       final int SYMBOL_RBRACKET          = 19;  // ']'
       final int SYMBOL_LBRACE            = 20;  // '{'
       final int SYMBOL_RBRACE            = 21;  // '}'
       final int SYMBOL_PLUS              = 22;  // '+'
       final int SYMBOL_LT                = 23;  // '<'
       final int SYMBOL_LTEQ              = 24;  // '<='
       final int SYMBOL_EQ                = 25;  // '='
       final int SYMBOL_EQEQ              = 26;  // '=='
       final int SYMBOL_GT                = 27;  // '>'
       final int SYMBOL_GTEQ              = 28;  // '>='
       final int SYMBOL_BOOLEAN           = 29;  // boolean
       final int SYMBOL_CHAR2             = 30;  // char
       final int SYMBOL_CLASS             = 31;  // class
       final int SYMBOL_ELSE              = 32;  // else
       final int SYMBOL_FALSE             = 33;  // false
       final int SYMBOL_ID                = 34;  // id
       final int SYMBOL_IF                = 35;  // if
       final int SYMBOL_INT               = 36;  // int
       final int SYMBOL_NUM               = 37;  // num
       final int SYMBOL_RETURN            = 38;  // return
       final int SYMBOL_SCAPESEQ          = 39;  // ScapeSeq
       final int SYMBOL_STRUCT            = 40;  // struct
       final int SYMBOL_TRUE              = 41;  // true
       final int SYMBOL_VOID              = 42;  // void
       final int SYMBOL_WHILE             = 43;  // while
       final int SYMBOL_ARG               = 44;  // <arg>
       final int SYMBOL_ARITH_OP          = 45;  // <arith_op>
       final int SYMBOL_BLOCK             = 46;  // <Block>
       final int SYMBOL_BOOL_LITERAL      = 47;  // <bool_literal>
       final int SYMBOL_CHAR_LITERAL      = 48;  // <char_literal>
       final int SYMBOL_COND_OP           = 49;  // <cond_op>
       final int SYMBOL_DECLARATION       = 50;  // <declaration>
       final int SYMBOL_EQ_OP             = 51;  // <eq_op>
       final int SYMBOL_EXPRESSION        = 52;  // <expression>
       final int SYMBOL_FORMALPARAMETERS  = 53;  // <formalParameters>
       final int SYMBOL_INT_LITERAL       = 54;  // <int_literal>
       final int SYMBOL_LITERAL           = 55;  // <literal>
       final int SYMBOL_LOCATION          = 56;  // <location>
       final int SYMBOL_METHODCALL        = 57;  // <methodCall>
       final int SYMBOL_METHODDECLARATION = 58;  // <methodDeclaration>
       final int SYMBOL_METHODFIRM        = 59;  // <methodFirm>
       final int SYMBOL_OP                = 60;  // <op>
       final int SYMBOL_PARAMETER         = 61;  // <parameter>
       final int SYMBOL_PARAMETERTYPE     = 62;  // <parameterType>
       final int SYMBOL_PROGRAM           = 63;  // <program>
       final int SYMBOL_REL_OP            = 64;  // <rel_op>
       final int SYMBOL_STATEMENT         = 65;  // <statement>
       final int SYMBOL_STRUCTDECLARATION = 66;  // <structDeclaration>
       final int SYMBOL_VARDECLARATION    = 67;  // <varDeclaration>
       final int SYMBOL_VARTYPE           = 68;  // <varType>
    };

    private interface RuleConstants
    {
       final int RULE_PROGRAM_CLASS_ID_LBRACE_RBRACE               =  0;  // <program> ::= class id '{' <declaration> '}'
       final int RULE_DECLARATION                                  =  1;  // <declaration> ::= <structDeclaration>
       final int RULE_DECLARATION2                                 =  2;  // <declaration> ::= <varDeclaration>
       final int RULE_DECLARATION3                                 =  3;  // <declaration> ::= <methodDeclaration>
       final int RULE_VARDECLARATION_ID_SEMI                       =  4;  // <varDeclaration> ::= <varType> id ';'
       final int RULE_VARDECLARATION_ID_LBRACKET_NUM_RBRACKET_SEMI =  5;  // <varDeclaration> ::= <varType> id '[' num ']' ';'
       final int RULE_STRUCTDECLARATION_STRUCT_ID_LBRACE_RBRACE    =  6;  // <structDeclaration> ::= struct id '{' <varDeclaration> '}'
       final int RULE_VARTYPE_INT                                  =  7;  // <varType> ::= int
       final int RULE_VARTYPE_CHAR                                 =  8;  // <varType> ::= char
       final int RULE_VARTYPE_BOOLEAN                              =  9;  // <varType> ::= boolean
       final int RULE_VARTYPE_STRUCT_ID                            = 10;  // <varType> ::= struct id
       final int RULE_VARTYPE                                      = 11;  // <varType> ::= <structDeclaration>
       final int RULE_VARTYPE_VOID                                 = 12;  // <varType> ::= void
       final int RULE_METHODDECLARATION                            = 13;  // <methodDeclaration> ::= <methodFirm> <Block>
       final int RULE_METHODFIRM_INT_ID_LPARAN_RPARAN              = 14;  // <methodFirm> ::= int id '(' <formalParameters> ')'
       final int RULE_METHODFIRM_CHAR_ID_LPARAN_RPARAN             = 15;  // <methodFirm> ::= char id '(' <formalParameters> ')'
       final int RULE_METHODFIRM_BOOLEAN_ID_LPARAN_RPARAN          = 16;  // <methodFirm> ::= boolean id '(' <formalParameters> ')'
       final int RULE_METHODFIRM_VOID_ID_LPARAN_RPARAN             = 17;  // <methodFirm> ::= void id '(' <formalParameters> ')'
       final int RULE_METHODFIRM_INT_ID_LPARAN_RPARAN2             = 18;  // <methodFirm> ::= int id '(' ')'
       final int RULE_METHODFIRM_CHAR_ID_LPARAN_RPARAN2            = 19;  // <methodFirm> ::= char id '(' ')'
       final int RULE_METHODFIRM_BOOLEAN_ID_LPARAN_RPARAN2         = 20;  // <methodFirm> ::= boolean id '(' ')'
       final int RULE_METHODFIRM_VOID_ID_LPARAN_RPARAN2            = 21;  // <methodFirm> ::= void id '(' ')'
       final int RULE_FORMALPARAMETERS_COMMA                       = 22;  // <formalParameters> ::= <formalParameters> ',' <parameter>
       final int RULE_FORMALPARAMETERS                             = 23;  // <formalParameters> ::= <parameter>
       final int RULE_PARAMETER_ID                                 = 24;  // <parameter> ::= <parameterType> id
       final int RULE_PARAMETER_ID_LBRACKET_RBRACKET               = 25;  // <parameter> ::= <parameterType> id '[' ']'
       final int RULE_PARAMETERTYPE_INT                            = 26;  // <parameterType> ::= int
       final int RULE_PARAMETERTYPE_CHAR                           = 27;  // <parameterType> ::= char
       final int RULE_PARAMETERTYPE_BOOLEAN                        = 28;  // <parameterType> ::= boolean
       final int RULE_BLOCK_LBRACE_RBRACE                          = 29;  // <Block> ::= '{' <varDeclaration> <statement> '}'
       final int RULE_STATEMENT_IF_LPARAN_RPARAN_ELSE              = 30;  // <statement> ::= if '(' <expression> ')' <Block> else <Block>
       final int RULE_STATEMENT_WHILE_LPARAN_RPARAN                = 31;  // <statement> ::= while '(' <expression> ')' <Block>
       final int RULE_STATEMENT_RETURN_SEMI                        = 32;  // <statement> ::= return <expression> ';'
       final int RULE_STATEMENT_SEMI                               = 33;  // <statement> ::= <methodCall> ';'
       final int RULE_STATEMENT                                    = 34;  // <statement> ::= <Block>
       final int RULE_STATEMENT_EQ                                 = 35;  // <statement> ::= <location> '=' <expression>
       final int RULE_STATEMENT_SEMI2                              = 36;  // <statement> ::= <expression> ';'
       final int RULE_LOCATION_ID                                  = 37;  // <location> ::= id
       final int RULE_LOCATION_ID_LBRACKET_RBRACKET_DOT            = 38;  // <location> ::= id '[' <expression> ']' '.' <location>
       final int RULE_EXPRESSION                                   = 39;  // <expression> ::= <location>
       final int RULE_EXPRESSION2                                  = 40;  // <expression> ::= <methodCall>
       final int RULE_EXPRESSION3                                  = 41;  // <expression> ::= <literal>
       final int RULE_EXPRESSION4                                  = 42;  // <expression> ::= <expression> <op> <expression>
       final int RULE_EXPRESSION_MINUS                             = 43;  // <expression> ::= '-' <expression>
       final int RULE_EXPRESSION_EXCLAM                            = 44;  // <expression> ::= '!' <expression>
       final int RULE_EXPRESSION_LPARAN_RPARAN                     = 45;  // <expression> ::= '(' <expression> ')'
       final int RULE_METHODCALL_ID_LPARAN_RPARAN                  = 46;  // <methodCall> ::= id '(' <arg> ')'
       final int RULE_ARG                                          = 47;  // <arg> ::= <expression>
       final int RULE_OP                                           = 48;  // <op> ::= <arith_op>
       final int RULE_OP2                                          = 49;  // <op> ::= <rel_op>
       final int RULE_OP3                                          = 50;  // <op> ::= <eq_op>
       final int RULE_OP4                                          = 51;  // <op> ::= <cond_op>
       final int RULE_ARITH_OP_PLUS                                = 52;  // <arith_op> ::= '+'
       final int RULE_ARITH_OP_MINUS                               = 53;  // <arith_op> ::= '-'
       final int RULE_ARITH_OP_TIMES                               = 54;  // <arith_op> ::= '*'
       final int RULE_ARITH_OP_DIV                                 = 55;  // <arith_op> ::= '/'
       final int RULE_ARITH_OP_PERCENT                             = 56;  // <arith_op> ::= '%'
       final int RULE_REL_OP_LT                                    = 57;  // <rel_op> ::= '<'
       final int RULE_REL_OP_GT                                    = 58;  // <rel_op> ::= '>'
       final int RULE_REL_OP_LTEQ                                  = 59;  // <rel_op> ::= '<='
       final int RULE_REL_OP_GTEQ                                  = 60;  // <rel_op> ::= '>='
       final int RULE_EQ_OP_EQEQ                                   = 61;  // <eq_op> ::= '=='
       final int RULE_EQ_OP_EXCLAMEQ                               = 62;  // <eq_op> ::= '!='
       final int RULE_COND_OP_AMPAMP                               = 63;  // <cond_op> ::= '&&'
       final int RULE_COND_OP_PIPEPIPE                             = 64;  // <cond_op> ::= ' ||'
       final int RULE_LITERAL                                      = 65;  // <literal> ::= <int_literal>
       final int RULE_LITERAL2                                     = 66;  // <literal> ::= <char_literal>
       final int RULE_LITERAL3                                     = 67;  // <literal> ::= <bool_literal>
       final int RULE_INT_LITERAL_NUM                              = 68;  // <int_literal> ::= num
       final int RULE_CHAR_LITERAL_APOST_CHAR_APOST                = 69;  // <char_literal> ::= '' ' char ' ''
       final int RULE_BOOL_LITERAL_TRUE                            = 70;  // <bool_literal> ::= true
       final int RULE_BOOL_LITERAL_FALSE                           = 71;  // <bool_literal> ::= false
    };

   private static BufferedReader buffR;

    /***************************************************************
     * This class will run the engine, and needs a file called config.dat
     * in the current directory. This file should contain two lines,
     * The first should be the absolute path name to the .cgt file, the second
     * should be the source file you wish to parse.
     * @param args Array of arguments.
     ***************************************************************/
    //public static void main(String[] args)
    public void Parse()
    {
    	
    	java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Editor().setVisible(true);
            }
        });
    	
       String textToParse = "C:/Documents and Settings/Administrador/Mis documentos/Dave's Files/La U/Ciclo 8/Compiladores 2/Compis/Miniproyecto/file1"; 
       String compiledGrammar = "C:/Documents and Settings/Administrador/Mis documentos/Dave's Files/La U/Ciclo 8/Compiladores 2/Compis/Miniproyecto/decaf2r.cgt";
      
       /**
       try
       {
           //buffR = new BufferedReader(new FileReader(new File("C:/Documents and Settings/Administrador/Mis documentos/Dave's Files/La U/Ciclo 8/Compiladores 2/Compis/Miniproyecto/src/config.dat")));
           //compiledGrammar = buffR.readLine();
           //textToParse = buffR.readLine();

           buffR.close();
       }
       catch(FileNotFoundException fnfex)
       {
           System.out.println("Config File was not found.\n\n" +
                              "Please place it in the current directory.");
           System.exit(1);
       }
       catch(IOException ioex)
       {
          System.out.println("An error occured while reading config.dat.\n\n" +
                             "Please re-try ensuring the file can be read.");
          System.exit(1);
       }
       **/

       GOLDParser parser = new GOLDParser();

       try
       {
          parser.loadCompiledGrammar(compiledGrammar);
          parser.openFile(textToParse);
       }
       catch(ParserException parse)
       {
          System.out.println("**PARSER ERROR**\n" + parse.toString());
          System.exit(1);
       }

       boolean done = false;
       int response = -1;

       while(!done)
       {
          try
            {
                  response = parser.parse();
            }
            catch(ParserException parse)
            {
                System.out.println("**PARSER ERROR**\n" + parse.toString());
                System.exit(1);
            }

            switch(response)
            {
               case gpMsgTokenRead:
                   /* A token was read by the parser. The Token Object can be accessed
                      through the CurrentToken() property:  Parser.CurrentToken */
                   break;

               case gpMsgReduction:
                   /* This message is returned when a rule was reduced by the parse engine.
                      The CurrentReduction property is assigned a Reduction object
                      containing the rule and its related tokens. You can reassign this
                      property to your own customized class. If this is not the case,
                      this message can be ignored and the Reduction object will be used
                      to store the parse tree.  */

                      switch(parser.currentReduction().getParentRule().getTableIndex())
                      {
                         case RuleConstants.RULE_PROGRAM_CLASS_ID_LBRACE_RBRACE:
                            //<program> ::= class id '{' <declaration> '}'
                            break;
                         case RuleConstants.RULE_DECLARATION:
                            //<declaration> ::= <structDeclaration>
                            break;
                         case RuleConstants.RULE_DECLARATION2:
                            //<declaration> ::= <varDeclaration>
                            break;
                         case RuleConstants.RULE_DECLARATION3:
                            //<declaration> ::= <methodDeclaration>
                            break;
                         case RuleConstants.RULE_VARDECLARATION_ID_SEMI:
                            //<varDeclaration> ::= <varType> id ';'
                            break;
                         case RuleConstants.RULE_VARDECLARATION_ID_LBRACKET_NUM_RBRACKET_SEMI:
                            //<varDeclaration> ::= <varType> id '[' num ']' ';'
                            break;
                         case RuleConstants.RULE_STRUCTDECLARATION_STRUCT_ID_LBRACE_RBRACE:
                            //<structDeclaration> ::= struct id '{' <varDeclaration> '}'
                            break;
                         case RuleConstants.RULE_VARTYPE_INT:
                            //<varType> ::= int
                            break;
                         case RuleConstants.RULE_VARTYPE_CHAR:
                            //<varType> ::= char
                            break;
                         case RuleConstants.RULE_VARTYPE_BOOLEAN:
                            //<varType> ::= boolean
                            break;
                         case RuleConstants.RULE_VARTYPE_STRUCT_ID:
                            //<varType> ::= struct id
                            break;
                         case RuleConstants.RULE_VARTYPE:
                            //<varType> ::= <structDeclaration>
                            break;
                         case RuleConstants.RULE_VARTYPE_VOID:
                            //<varType> ::= void
                            break;
                         case RuleConstants.RULE_METHODDECLARATION:
                            //<methodDeclaration> ::= <methodFirm> <Block>
                            break;
                         case RuleConstants.RULE_METHODFIRM_INT_ID_LPARAN_RPARAN:
                            //<methodFirm> ::= int id '(' <formalParameters> ')'
                            break;
                         case RuleConstants.RULE_METHODFIRM_CHAR_ID_LPARAN_RPARAN:
                            //<methodFirm> ::= char id '(' <formalParameters> ')'
                            break;
                         case RuleConstants.RULE_METHODFIRM_BOOLEAN_ID_LPARAN_RPARAN:
                            //<methodFirm> ::= boolean id '(' <formalParameters> ')'
                            break;
                         case RuleConstants.RULE_METHODFIRM_VOID_ID_LPARAN_RPARAN:
                            //<methodFirm> ::= void id '(' <formalParameters> ')'
                            break;
                         case RuleConstants.RULE_METHODFIRM_INT_ID_LPARAN_RPARAN2:
                            //<methodFirm> ::= int id '(' ')'
                            break;
                         case RuleConstants.RULE_METHODFIRM_CHAR_ID_LPARAN_RPARAN2:
                            //<methodFirm> ::= char id '(' ')'
                            break;
                         case RuleConstants.RULE_METHODFIRM_BOOLEAN_ID_LPARAN_RPARAN2:
                            //<methodFirm> ::= boolean id '(' ')'
                            break;
                         case RuleConstants.RULE_METHODFIRM_VOID_ID_LPARAN_RPARAN2:
                            //<methodFirm> ::= void id '(' ')'
                            break;
                         case RuleConstants.RULE_FORMALPARAMETERS_COMMA:
                            //<formalParameters> ::= <formalParameters> ',' <parameter>
                            break;
                         case RuleConstants.RULE_FORMALPARAMETERS:
                            //<formalParameters> ::= <parameter>
                            break;
                         case RuleConstants.RULE_PARAMETER_ID:
                            //<parameter> ::= <parameterType> id
                            break;
                         case RuleConstants.RULE_PARAMETER_ID_LBRACKET_RBRACKET:
                            //<parameter> ::= <parameterType> id '[' ']'
                            break;
                         case RuleConstants.RULE_PARAMETERTYPE_INT:
                            //<parameterType> ::= int
                            break;
                         case RuleConstants.RULE_PARAMETERTYPE_CHAR:
                            //<parameterType> ::= char
                            break;
                         case RuleConstants.RULE_PARAMETERTYPE_BOOLEAN:
                            //<parameterType> ::= boolean
                            break;
                         case RuleConstants.RULE_BLOCK_LBRACE_RBRACE:
                            //<Block> ::= '{' <varDeclaration> <statement> '}'
                            break;
                         case RuleConstants.RULE_STATEMENT_IF_LPARAN_RPARAN_ELSE:
                            //<statement> ::= if '(' <expression> ')' <Block> else <Block>
                            break;
                         case RuleConstants.RULE_STATEMENT_WHILE_LPARAN_RPARAN:
                            //<statement> ::= while '(' <expression> ')' <Block>
                            break;
                         case RuleConstants.RULE_STATEMENT_RETURN_SEMI:
                            //<statement> ::= return <expression> ';'
                            break;
                         case RuleConstants.RULE_STATEMENT_SEMI:
                            //<statement> ::= <methodCall> ';'
                            break;
                         case RuleConstants.RULE_STATEMENT:
                            //<statement> ::= <Block>
                            break;
                         case RuleConstants.RULE_STATEMENT_EQ:
                            //<statement> ::= <location> '=' <expression>
                            break;
                         case RuleConstants.RULE_STATEMENT_SEMI2:
                            //<statement> ::= <expression> ';'
                            break;
                         case RuleConstants.RULE_LOCATION_ID:
                            //<location> ::= id
                            break;
                         case RuleConstants.RULE_LOCATION_ID_LBRACKET_RBRACKET_DOT:
                            //<location> ::= id '[' <expression> ']' '.' <location>
                            break;
                         case RuleConstants.RULE_EXPRESSION:
                            //<expression> ::= <location>
                            break;
                         case RuleConstants.RULE_EXPRESSION2:
                            //<expression> ::= <methodCall>
                            break;
                         case RuleConstants.RULE_EXPRESSION3:
                            //<expression> ::= <literal>
                            break;
                         case RuleConstants.RULE_EXPRESSION4:
                            //<expression> ::= <expression> <op> <expression>
                            break;
                         case RuleConstants.RULE_EXPRESSION_MINUS:
                            //<expression> ::= '-' <expression>
                            break;
                         case RuleConstants.RULE_EXPRESSION_EXCLAM:
                            //<expression> ::= '!' <expression>
                            break;
                         case RuleConstants.RULE_EXPRESSION_LPARAN_RPARAN:
                            //<expression> ::= '(' <expression> ')'
                            break;
                         case RuleConstants.RULE_METHODCALL_ID_LPARAN_RPARAN:
                            //<methodCall> ::= id '(' <arg> ')'
                            break;
                         case RuleConstants.RULE_ARG:
                            //<arg> ::= <expression>
                            break;
                         case RuleConstants.RULE_OP:
                            //<op> ::= <arith_op>
                            break;
                         case RuleConstants.RULE_OP2:
                            //<op> ::= <rel_op>
                            break;
                         case RuleConstants.RULE_OP3:
                            //<op> ::= <eq_op>
                            break;
                         case RuleConstants.RULE_OP4:
                            //<op> ::= <cond_op>
                            break;
                         case RuleConstants.RULE_ARITH_OP_PLUS:
                            //<arith_op> ::= '+'
                            break;
                         case RuleConstants.RULE_ARITH_OP_MINUS:
                            //<arith_op> ::= '-'
                            break;
                         case RuleConstants.RULE_ARITH_OP_TIMES:
                            //<arith_op> ::= '*'
                            break;
                         case RuleConstants.RULE_ARITH_OP_DIV:
                            //<arith_op> ::= '/'
                            break;
                         case RuleConstants.RULE_ARITH_OP_PERCENT:
                            //<arith_op> ::= '%'
                            break;
                         case RuleConstants.RULE_REL_OP_LT:
                            //<rel_op> ::= '<'
                            break;
                         case RuleConstants.RULE_REL_OP_GT:
                            //<rel_op> ::= '>'
                            break;
                         case RuleConstants.RULE_REL_OP_LTEQ:
                            //<rel_op> ::= '<='
                            break;
                         case RuleConstants.RULE_REL_OP_GTEQ:
                            //<rel_op> ::= '>='
                            break;
                         case RuleConstants.RULE_EQ_OP_EQEQ:
                            //<eq_op> ::= '=='
                            break;
                         case RuleConstants.RULE_EQ_OP_EXCLAMEQ:
                            //<eq_op> ::= '!='
                            break;
                         case RuleConstants.RULE_COND_OP_AMPAMP:
                            //<cond_op> ::= '&&'
                            break;
                         case RuleConstants.RULE_COND_OP_PIPEPIPE:
                            //<cond_op> ::= ' ||'
                            break;
                         case RuleConstants.RULE_LITERAL:
                            //<literal> ::= <int_literal>
                            break;
                         case RuleConstants.RULE_LITERAL2:
                            //<literal> ::= <char_literal>
                            break;
                         case RuleConstants.RULE_LITERAL3:
                            //<literal> ::= <bool_literal>
                            break;
                         case RuleConstants.RULE_INT_LITERAL_NUM:
                            //<int_literal> ::= num
                            break;
                         case RuleConstants.RULE_CHAR_LITERAL_APOST_CHAR_APOST:
                            //<char_literal> ::= '' ' char ' ''
                            break;
                         case RuleConstants.RULE_BOOL_LITERAL_TRUE:
                            //<bool_literal> ::= true
                            break;
                         case RuleConstants.RULE_BOOL_LITERAL_FALSE:
                            //<bool_literal> ::= false
                            break;
                      }

                          //Parser.Reduction = //Object you created to store the rule

                    // ************************************** log file
                    System.out.println("gpMsgReduction");
                    Reduction myRed = parser.currentReduction();
                    System.out.println(myRed.getParentRule().getText());
                    // ************************************** end log

                    break;

                case gpMsgAccept:
                    /* The program was accepted by the parsing engine */

                    // ************************************** log file
                    System.out.println("gpMsgAccept");
                    // ************************************** end log

                    done = true;

                    break;

                case gpMsgLexicalError:
                    /* Place code here to handle a illegal or unrecognized token
                           To recover, pop the token from the stack: Parser.PopInputToken */

                    // ************************************** log file
                    System.out.println("gpMsgLexicalError");
                    // ************************************** end log

                    parser.popInputToken();

                    break;

                case gpMsgNotLoadedError:
                    /* Load the Compiled Grammar Table file first. */

                    // ************************************** log file
                    System.out.println("gpMsgNotLoadedError");
                    // ************************************** end log

                    done = true;

                    break;

                case gpMsgSyntaxError:
                    /* This is a syntax error: the source has produced a token that was
                           not expected by the LALR State Machine. The expected tokens are stored
                           into the Tokens() list. To recover, push one of the
                              expected tokens onto the parser's input queue (the first in this case):
                           You should limit the number of times this type of recovery can take
                           place. */

                    done = true;

                    Token theTok = parser.currentToken();
                    System.out.println("Token not expected: " + (String)theTok.getData());

                    // ************************************** log file
                    System.out.println("gpMsgSyntaxError");
                    // ************************************** end log

                    break;

                case gpMsgCommentError:
                    /* The end of the input was reached while reading a comment.
                             This is caused by a comment that was not terminated */

                    // ************************************** log file
                    System.out.println("gpMsgCommentError");
                    // ************************************** end log

                    done = true;

                              break;

                case gpMsgInternalError:
                    /* Something horrid happened inside the parser. You cannot recover */

                    // ************************************** log file
                    System.out.println("gpMsgInternalError");
                    // ************************************** end log

                    done = true;

                    break;
            }
            showTree( this.arbol, getRoot(), parser.currentReduction());
        }
        try
        { 
        	parser.closeFile();
        }
        catch(ParserException parse)
        {
            System.out.println("**PARSER ERROR**\n" + parse.toString());
            System.exit(1);
        }
    }
    
    public DefaultMutableTreeNode getRoot() {
        return root;
    }
    
    public static JTree getJTree(){
    	return jtree;
    }
public static void showTree(DefaultTreeModel tree, DefaultMutableTreeNode root, Reduction reduccion){
        
        for(int i=0; i<reduccion.getTokenCount(); i++)
        {
            if(reduccion.getToken(i).getKind()==0){
                //Here comes when there is a non terminal. Example: <a> ::= 'b' <a> | 'c'
                Reduction red = (Reduction)reduccion.getToken(i).getData();
                String rule = red.getParentRule().definition();
                String rule_name = reduccion.getToken(i).getName();
                System.out.println(" + "+rule_name+ " + ."+rule+".");

                //TODO hacer comparaciones...

                DefaultMutableTreeNode child = new DefaultMutableTreeNode(reduccion.getToken(i).getName());
                showTree(tree, child, (Reduction)reduccion.getToken(i).getData());
                tree.insertNodeInto(child, root, i);
            }

            else{
                // Here comes when there is a terminal -> token
                // Token -> (name token, token lexeme)
                // This will be a leaf

                String token_name = reduccion.getToken(i).getName();
                String token_lexeme = (String)reduccion.getToken(i).getData();
                String txt_in_leaf = "";
                if(token_name.equals(token_lexeme) == true && token_name.equals("id")==false){
                    txt_in_leaf = token_name+"";
                }
                else{
                    txt_in_leaf = token_name + " = "+ token_lexeme;
                }
                System.out.println(" - "+txt_in_leaf);
                DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(txt_in_leaf);
                tree.insertNodeInto(leaf, root, i);
            }
        }
    }

	private static DefaultMutableTreeNode root = new DefaultMutableTreeNode("Program");
	private static DefaultTreeModel arbol = new DefaultTreeModel(root);
	private GOLDParser parser = new GOLDParser();
	private boolean error = false;
	private String error_log = "";
	private String debug_log = "";
	private String output_log = "";
	public static JTree jtree = new JTree(arbol);
}
